//
//  ZhongjiangjiluVC.m
//  SSC
//
//  Created by 红沙尘 on 17/6/10.
//  Copyright © 2017年 红沙尘. All rights reserved.
//

#import "ZhongjiangjiluVC.h"
#import "ZhongjiangjiluCell.h"

@interface ZhongjiangjiluVC ()

@end

@implementation ZhongjiangjiluVC

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    return [super initWithNibName:NSStringFromClass([self.superclass class]) bundle:nibBundleOrNil];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setTitle:@"中奖记录"];
}

#pragma mark - 网络数据

- (void)loadData {
    [super loadData];
    
    WeakSelf
    __weak UITableView *weakTableView = mainTableView;
    
    [SSCRequest orderWinListStartdt:[MTool formartDate:startField.text]
                              enddt:[MTool formartDate:endField.text]
                               page:page
                            success:^(NSDictionary *responseObject)
    {
        [weakTableView.mj_header endRefreshing];
        [weakTableView.mj_footer endRefreshing];

        [weakSelf loadWithArray:[NSString safeArray:responseObject[@"data"]]];
        
    } fail:^(NSError *error) {
        [weakTableView.mj_header endRefreshing];
        [weakTableView.mj_footer endRefreshing];
    }];
}


#pragma mark - table

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ZhongjiangjiluCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ZhongjiangjiluCell"];
    
    [cell loadWithDict:dataArray[indexPath.row]];
    
    return cell;
}

#pragma mark -

- (void)setupUI {
    [super setupUI];
        
    mainTableView.rowHeight = 132;
    mainTableView.estimatedRowHeight = 132;
    
    [mainTableView registerNib:[UINib nibWithNibName:@"ZhongjiangjiluCell" bundle:nil]
        forCellReuseIdentifier:@"ZhongjiangjiluCell"];
    
    [mainTableView reloadData];
}

@end
